
import { useRequest } from 'umi';

import { getDicListByTypeID } from '../service';

export const useDictionaryTable = () => {
  const getTableDataSource = useRequest(
    (id: string) => {
      return getDicListByTypeID(id);
    },
    {
      manual: true,
      onSuccess(data: any, params: [id: string]): void {},
    },
  );

  const reloadTableDataSource = (id: string) => getTableDataSource.run(id);
  const tableData = getTableDataSource?.data?.obj ?? [];
  const tableLoading = getTableDataSource.loading;

  return {
    reloadTableDataSource,
    tableDataSource: tableData,
    tableLoading,
  };
};
